package model;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public class Termin {

	private static int terminIdCounter = 0;

	private int terminId;
	
	private Calendar calendar;

	private Anwendung anwendung;

	private Therapeut therapeut;

	private Raum raum;

	private ArrayList<Patient> patienten;

	public Termin(Date datum, int hours, int minutes, Anwendung anwendung,
			Therapeut therapeut, Raum raum) {
		terminId = terminIdCounter++;
		calendar = new GregorianCalendar();
		calendar.setTime(datum);
		calendar.set(Calendar.HOUR_OF_DAY, hours);
		calendar.set(Calendar.MINUTE, minutes);
		this.anwendung = anwendung;
		this.therapeut = therapeut;
		this.raum = raum;
		patienten = new ArrayList<Patient>();
	}

	public int getTerminId() {
		return terminId;
	}

	public Date getDatum() {
		return calendar.getTime();
	}

	public void setDatum(Date datum) {
		calendar.setTime(datum);
	}

	public int getHours() {
		return calendar.get(Calendar.HOUR_OF_DAY);
	}

	public void setHours(int hours) {
		calendar.set(Calendar.HOUR_OF_DAY, hours);
	}

	public int getMinutes() {
		return calendar.get(Calendar.MINUTE);
	}

	public void setMinutes(int minutes) {
		calendar.set(Calendar.MINUTE, minutes);
	}

	public Anwendung getAnwendung() {
		return anwendung;
	}

	public void setAnwendung(Anwendung anwendung) {
		this.anwendung = anwendung;
	}

	public Therapeut getTherapeut() {
		return therapeut;
	}

	public void setTherapeut(Therapeut therapeut) {
		this.therapeut = therapeut;
	}

	public Raum getRaum() {
		return raum;
	}

	public void setRaum(Raum raum) {
		this.raum = raum;
	}

	public List<Patient> getPatienten() {
		return Collections.unmodifiableList(patienten);
	}

	public void addPatient(Patient patient) {
		patienten.add(patient);
	}

	public void removePatient(Patient patient) {
		patienten.remove(patient);
	}

	public void clearPatienten() {
		patienten.clear();
	}

	public boolean containsPatient(Patient patient) {
		return patienten.contains(patient);
	}

	@Override
	public String toString() {
		DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm");
		return terminId + ": " + formatter.format(calendar.getTime());
	}

}
